import { IWork } from '@lib/types';
import ajax from '@lib/ajax';

const URL = "work/list";

interface IRequest {
	id: string;
	page: number;
	sort: "time" | "vote" | "hot" | "create";
}

interface IResponse {
	total: number;
	size: number;
	list: IWork[];
}

export default async function(req: IRequest) {
	const res = await ajax({
		url: URL + "/" + req.id,
		query: {
			page: req.page.toString(),
			sort: req.sort
		}
	});
	if (res.success) {
		const data = (res.data as IResponse);
		return data;
	} else {
		return new Error(res.error);
	}
}